Imports BAL
Imports MyClasses
Imports System.Data.DataSet
Imports System.Configuration
Imports DAL
Public Class frmPayment


    Dim Payment As CPayment
    Dim PaymentDet() As CPaymentDet
    Dim blnFlagFromto As Boolean
    Dim blnFlagName As Boolean = False
    Dim intPaymentRecNo As Integer = 0


    Private Sub dtpickerDate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpickerDate.KeyDown
        If e.KeyCode = Keys.Enter Then txtCustVend.Focus()
    End Sub

    '****************************************************************************
    'Written By:- Vinit(2008/01/24)
    'Selecting Vendor Record According to VendorID
    '***********************
    Private Sub cmbName_DropDownClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbName.DropDownClosed
        'If blnFlagName = False Then Exit Sub
        Dim intPayerID As Integer
        Dim intFlag As Boolean
        Try
            If cmbName.SelectedIndex > 0 Then
                intPayerID = Convert.ToInt32(cmbName.SelectedValue)
                intFlag = LoadPendingBills(intPayerID)
                '*************************************************************
                'Modified By:- Vinit (20071128)
                '==============================
                If Me.rdbtnPayment.Checked = True Then
                    Me.txtCustVend.Text = BCommon.GetSequentialCode("VENDOR") & Trim(Me.cmbName.SelectedValue.ToString())    
                ElseIf Me.rdbtnReceipt.Checked = True Then                    
                    Me.txtCustVend.Text = BCommon.GetSequentialCode("CUST") & Trim(Me.cmbName.SelectedValue.ToString())                
                End If
                '==============================
                Me.txtRemark.Text = ""
            Else
                Call ClearData()
                txtCustVend.Text = String.Empty
            End If

            'Check the Grid is having row or not then set the focus
            If intFlag = True Then
                If FGPaymentdetails.Rows.Count > 1 Then
                    FGPaymentdetails.Row = 1
                    FGPaymentdetails.Col = 6
                    FGPaymentdetails.Focus()
                End If
            Else
                If FGPaymentdetails.Rows.Count > 0 Then
                    FGPaymentdetails.Rows.RemoveRange(1, FGPaymentdetails.Rows.Count - 1)
                End If
                FGPaymentdetails.Rows.Count = 21
                cmbName.Focus()
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "cmbName_DropDownClosed")
        End Try
    End Sub
    
    Private Sub cmbName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbName.KeyDown
        If e.Alt Then Exit Sub
        Dim intPayerID As Integer
        If e.KeyCode = Keys.Enter Then
            If cmbName.SelectedIndex > 0 Then
                intPayerID = Convert.ToInt32(cmbName.SelectedValue)
                Call LoadPendingBills(intPayerID)
                '*************************************************************
                'Modified By:- Vinit (20071128)
                '==============================
                If Me.rdbtnPayment.Checked = True Then
                    Me.txtCustVend.Text = BCommon.GetSequentialCode("VENDOR") & Trim(Me.cmbName.SelectedValue.ToString())
                ElseIf Me.rdbtnReceipt.Checked = True Then
                    Me.txtCustVend.Text = BCommon.GetSequentialCode("CUST") & Trim(Me.cmbName.SelectedValue.ToString())
                End If
                '==============================
                Me.txtRemark.Text = ""
            Else
                Call ClearData()
                txtCustVend.Text = String.Empty
            End If
            If FGPaymentdetails.Rows.Count > 1 Then
                FGPaymentdetails.Row = 1
                FGPaymentdetails.Col = 6
                FGPaymentdetails.Focus()
            End If
        End If
    End Sub

    Private Sub txtRemark_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtRemark.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnSave.Focus()
        Else
            If BCommon.ValidateText(e.KeyCode, "ALFTEXT", False) = False Then
                e.SuppressKeyPress = True
            End If
        End If
    End Sub

    Private Sub frmPayment_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Me.MdiParent = Nothing
    End Sub

    Private Sub frmPayment_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Not (ConfigurationManager.AppSettings("FormMode") = "R") Then
                If intPaymentRecNo > 0 Then
                    e.Cancel = False
                Else
                    If isUpdate() Then
                        Select Case BCommon.ShowMsgError(10081, "YNC")
                            Case Windows.Forms.DialogResult.Yes
                                If ValidateInfo() = True Then
                                    Call SaveData()
                                Else
                                    e.Cancel = True
                                End If
                            Case Windows.Forms.DialogResult.Cancel
                                e.Cancel = True
                            Case Windows.Forms.DialogResult.No
                        End Select
                    End If
                End If
                intPaymentRecNo = 0
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnSave_Click")
        End Try
    End Sub

    Private Sub frmPayment_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If e.KeyCode = Keys.F1 Then
            'Rauhl_ITS@20073012 : Add following code display help
            e.SuppressKeyPress = True
            Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Payment Receipt")
        End If
    End Sub

    Private Sub frmPayment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BCommon.SetFormStandards(Me)
        Call DisplayData()
        Me.rdbtnPayment.Enabled = True
        Me.rdbtnReceipt.Enabled = True
        FGPaymentdetails.Cols(6).DataType = System.Type.GetType("System.Decimal")
    End Sub
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        
        Try
            If ValidateInfo() = True Then
                Call SaveData()
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnSave_Click")
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Call ClearData()
    End Sub

    Private Sub LoadGridCombobox()
        Try
            BCommon.SetComboValues(cCmbPayMode, "PAYMODE")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "LoadGridCombobox")
        End Try
    End Sub

    Private Sub DisplayData()
        Try
            Call SetDatepickerMaxMinDate()  'Divya  22/11/2007
            Call ClearData()
            Call LoadGridCombobox()
            'Divya 30/01/2008 : Added for ReadOnly fields
            BCommon.SetTextReadOnly(txtVoucherno)
            BCommon.SetTextReadOnly(txtPaidAmount)
            BCommon.SetTextReadOnly(txtAmount)
            BCommon.SetTextReadOnly(txtBalance)
            '>>End
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "DisplayData")

        End Try
    End Sub
    'Divya 22/11/2007
    Private Sub SetDatepickerMaxMinDate()
        Dim dtDatePkr As DataTable
        Try
            dtDatePkr = BCommon.GetDatePicker()
            dtpickerDate.MinDate = dtDatePkr.Rows(0).Item("fin_start_dt")
            dtpickerDate.MaxDate = dtDatePkr.Rows(0).Item("fin_end_dt")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetDatepickerMaxMinDate")
        End Try
    End Sub
    Private Sub SaveData()
        Try
            If DPayment.SavePayDetails(SetPayment, SetPaymentDet, IIf(btnSave.Text = "&Save", "S", "U")) > 0 Then BCommon.ShowMsgError(3) Else BCommon.ShowMsgError(4)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SaveData")

        End Try
        Call ClearData()
    End Sub

    Private Function SetPayment() As CPayment
        Payment = New CPayment
        Try
            With Payment
                If Me.rdbtnReceipt.Checked = True Then
                    .PayType = "Recp"
                    .BillType = "Sale"
                ElseIf Me.rdbtnPayment.Checked = True Then
                    .PayType = "Pay"
                    .BillType = "Purchase"
                End If
                
                If txtAmount.Text <> "" Then
                    .PayAmount = Convert.ToDouble(txtAmount.Text.ToString()) 'Total Amount
                Else
                    .PayAmount = 0.0
                End If
                .PayRcptnum = Trim(txtVoucherno.Text)
                .PayerID = cmbName.SelectedValue            'Vendor ID
                .PayDate = dtpickerDate.Value.Date                'Paid Date
                .PayMode = cCmbPayMode.SelectedValue
                .Concession = 0.0
                .Description = Trim(txtRemark.Text)         'Remarks
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetData")
        End Try
        Return Payment
    End Function


    Private Function SetPaymentDet() As CPaymentDet()
        ReDim PaymentDet(FGPaymentdetails.Rows.Count - 2)
        Dim intcount As Integer
        Dim intPaidCount As Integer = 0
        Try
            For intcount = 0 To FGPaymentdetails.Rows.Count - 2
                If FGPaymentdetails.Item(intcount + 1, 6) <> 0.0 Or FGPaymentdetails.Item(intcount + 1, 6) <> Nothing Then
                    PaymentDet(intPaidCount) = New CPaymentDet
                    With PaymentDet(intPaidCount)
                        .BillID = FGPaymentdetails.Item(intcount + 1, 1)   'User Endered Amount Value
                        .Amount = Convert.ToDouble(FGPaymentdetails.Item(intcount + 1, 6))
                    End With
                    intPaidCount = intPaidCount + 1
                End If
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetData")
        End Try
        Return PaymentDet
    End Function


    Private Sub ClearData()
        Try
            blnFlagName = False
            blnFlagFromto = False
            '*******************************************************
            Me.rdbtnReceipt.Checked = True
            txtVoucherno.Text = BCommon.GetSequentialID("RCPTNUM")
            Me.lblName.Text = "C&ustomer"
            BCommon.SetComboValues(cmbName, BCustomer.GetCustomer(), "CustId", "dispname")
            '===========================

            cmbName.SelectedIndex = -1
            txtRemark.Text = ""
            dtpickerDate.Value = Now
            lblRs.Text = ConfigurationManager.AppSettings("Currency")
            txtPaidAmount.Text = "0.00"
            txtAmount.Text = "0.00"
            txtBalance.Text = "0.00"
            FGPaymentdetails.Rows.RemoveRange(1, FGPaymentdetails.Rows.Count - 1)
            'FGPaymentdetails.Rows.Count = 5
            'blnFlagFromto = True
            'blnFlagName = True

            '**************************************
            'Enable the Control
            'Modified By:-Vinit(20071026)
            'txtVoucherno.Enabled = True
            cmbName.Enabled = True
            dtpickerDate.Enabled = True
            txtCustVend.Text = ""
            txtCustVend.Enabled = True
            cCmbPayMode.Enabled = True
            txtRemark.Enabled = True
            txtAmount.Enabled = True
            btnSave.Visible = True
            With FGPaymentdetails
                .Enabled = True
                .Cols(0).Visible = False
                .Cols(5).Visible = True
                .Cols(7).Visible = True

                .Cols(3).DataType = System.Type.GetType("System.DateTime")
                .Cols(3).Format = "dd/MM/yy"

                .Cols(4).DataType = System.Type.GetType("System.Double")
                .Cols(5).DataType = System.Type.GetType("System.Double")
                .Cols(7).DataType = System.Type.GetType("System.Double")
                .Cols(8).DataType = System.Type.GetType("System.Double")

                .Cols(4).Format = "0.00"
                .Cols(5).Format = "0.00"
                .Cols(7).Format = "0.00"
                .Cols(8).Format = "0.00"
                .Rows.Count = 21

            End With

            txtBalance.Visible = True
            txtPaidAmount.Visible = True
            rdbtnPayment.Enabled = True
            rdbtnReceipt.Enabled = True
            'txtAmount.Location = New Point(462, 269)
            txtAmount.Location = New Point(719, 529)
            intPaymentRecNo = 0
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ClearData")
        End Try

    End Sub

    '****************************************************************************
    'Written By:- Vinit(20071024)
    'Selecting Vendor Record According to VendorID
    '***********************
    Private Function LoadPendingBills(ByVal intPayerID As Integer) As Boolean
        Dim dtbPaymentDetails As New DataTable
        Dim intcount As Integer = 1
        Try
            '*************************************************************
            'Modified By:- Vinit (20071128)
            '==============================
            If Me.rdbtnPayment.Checked = True Then
                dtbPaymentDetails = DPayment.LoadPendingBills(intPayerID, "Pay")
                If dtbPaymentDetails.Rows.Count = 0 Then
                    BCommon.ShowMsgError(10401)
                    Return False
                    Exit Function
                End If
            ElseIf Me.rdbtnReceipt.Checked = True Then
                dtbPaymentDetails = DPayment.LoadPendingBills(intPayerID, "Recp")
                If dtbPaymentDetails.Rows.Count = 0 Then
                    BCommon.ShowMsgError(10400)
                    Return False
                    Exit Function
                End If
            End If
            '==============================
            FGPaymentdetails.Rows.RemoveRange(1, FGPaymentdetails.Rows.Count - 1)

            'Set the Row count in the grid
            If dtbPaymentDetails.Rows.Count > 21 Then
                FGPaymentdetails.Rows.Count = dtbPaymentDetails.Rows.Count + 1
            ElseIf dtbPaymentDetails.Rows.Count = 21 Then
                FGPaymentdetails.Rows.Count = 22
            Else
                FGPaymentdetails.Rows.Count = 21
            End If

            For Each row As DataRow In dtbPaymentDetails.Rows
                FGPaymentdetails.Item(intcount, 1) = row.Item(0)                      'InvoiceId
                FGPaymentdetails.Item(intcount, 2) = row.Item(1)                      'SeqInvoiceID
                FGPaymentdetails.Item(intcount, 3) = row.Item(2)                      'InvoiceDate
                FGPaymentdetails.Item(intcount, 4) = Math.Round(CDbl(row.Item(3)), 2)                     'GrossAmount
                FGPaymentdetails.Item(intcount, 5) = Math.Round(CDbl(row.Item(4)), 2)                      'Paid Amount
                FGPaymentdetails.Item(intcount, 6) = 0.0                                'Amount
                FGPaymentdetails.Item(intcount, 7) = Math.Round(CDbl(row.Item(3)) - CDbl(row.Item(4)), 2)        'GrossAmount-PaidAmount
                FGPaymentdetails.Item(intcount, 8) = Math.Round(CDbl(row.Item(3)) - CDbl(row.Item(4)), 2)
                intcount = intcount + 1
            Next
            Call CalculateAmount()
            Return True
            '(grossamount-paidamount) AS balance
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "LoadPendingBills")
        End Try
    End Function
    Private Sub CalculateAmount()
        Try
            Dim totalpaidamt, totalamt, totalbal As Double
            Dim i As Integer = 0
            For i = 1 To FGPaymentdetails.Rows.Count - 1
                If IsNothing(FGPaymentdetails.Item(i, 1)) <> True Then
                    totalpaidamt = totalpaidamt + FGPaymentdetails.Item(i, 5)
                    If FGPaymentdetails.Item(i, 8) >= FGPaymentdetails.Item(i, 6) Then
                        totalamt = totalamt + FGPaymentdetails.Item(i, 6)
                        FGPaymentdetails.Item(i, 7) = Math.Round((FGPaymentdetails.Item(i, 8) - FGPaymentdetails.Item(i, 6)), 2)
                    Else
                        BCommon.ShowMsgError(10085)
                        FGPaymentdetails.Focus()
                        FGPaymentdetails.Item(i, 6) = ""
                        FGPaymentdetails.ColSel = 6
                        Exit Sub
                    End If
                    totalbal = totalbal + FGPaymentdetails.Item(i, 7)
                End If
            Next
            txtPaidAmount.Text = Format(totalpaidamt, "0.00")
            txtAmount.Text = Format(totalamt, "0.00")
            txtBalance.Text = Format(totalbal, "0.00")

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "CalculateAmount")
        End Try
    End Sub


    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Try
            'Dim form As New frmMasterBrowse
            'If Me.rdbtnPayment.Checked = True Then
            '    form.strSearch = "Payment"
            'ElseIf Me.rdbtnReceipt.Checked = True Then
            '    form.strSearch = "Receipt"
            'End If
            ''form.strSearch = "Payment"
            ''Rahul_ITS@20072612
            ''<<START
            'form.StartPosition = FormStartPosition.Manual
            'form.Height = MDIPharmacy.MdiScaleHeight
            'form.Width = MDIPharmacy.MdiScaleWidth
            'Dim pt As New Point
            'pt.Y = ((MDIPharmacy.MdiScaleHeight - form.Height) / 2) + MDIPharmacy.pnlHeading.Height + MDIPharmacy.MenuStrip.Height
            'pt.X = (MDIPharmacy.MdiScaleWidth - form.Width) / 2
            'form.Location = pt
            'form.ShowInTaskbar = False
            ''>>END
            'form.ShowDialog()
            'intPaymentRecNo = form.strRecordNo
            'If intPaymentRecNo > 0 Then
            '    Call ShowSearchRec(intPaymentRecNo)
            '    Call DisableControl()
            'End If
        Catch ex As Exception
            Exit Sub
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnSearch_Click")
        End Try
    End Sub


    '****************************************************************************
    'Written By:- Vinit(20071023)
    'Selecting Search Record
    '***********************
    Private Sub ShowSearchRec(ByVal intPaymentRecNo As Integer)
        Dim dtSearchRec1 As New DataTable
        Dim dtSearchRec2 As New DataTable
        Dim intcount As Integer = 1
        Try
            'Populate Grid Row and Col 
            If Me.rdbtnPayment.Checked = True Then
                dtSearchRec2 = DPayment.GetSearchItems(intPaymentRecNo, 2)
            ElseIf Me.rdbtnReceipt.Checked = True Then
                dtSearchRec2 = DPayment.GetSearchItems(intPaymentRecNo, 3)
            End If

            FGPaymentdetails.Rows.RemoveRange(1, FGPaymentdetails.Rows.Count - 1)
            If dtSearchRec2.Rows.Count > 0 Then
                'Set the row count in the grid
                If dtSearchRec2.Rows.Count > 21 Then
                    FGPaymentdetails.Rows.Count = dtSearchRec2.Rows.Count + 1
                ElseIf dtSearchRec2.Rows.Count = 21 Then
                    FGPaymentdetails.Rows.Count = 22
                Else
                    FGPaymentdetails.Rows.Count = 21
                End If

                'Populate the row data in the grid
                For Each row As DataRow In dtSearchRec2.Rows
                    With FGPaymentdetails
                        FGPaymentdetails.Item(intcount, 1) = row.Item(0)                      'InvoiceId
                        FGPaymentdetails.Item(intcount, 2) = row.Item(1)                      'SeqInvoiceID
                        FGPaymentdetails.Item(intcount, 3) = row.Item(2)                      'InvoiceDate
                        FGPaymentdetails.Item(intcount, 4) = Format(Math.Round(row.Item(3), 2), "0.00")                      'GrossAmount
                        'FGPaymentdetails.Item(intcount, 5) = row.Item(4)                      'Paid Amount
                        FGPaymentdetails.Item(intcount, 6) = Format(Math.Round(row.Item(5), 2), "0.00")                      'Amount
                        'FGPaymentdetails.Item(intcount, 7) = row.Item(3) - row.Item(4)        'GrossAmount-PaidAmount
                        'FGPaymentdetails.Item(intcount, 8) = row.Item(3) - row.Item(4)
                        intcount = intcount + 1
                    End With
                Next
            Else
                dtSearchRec2 = Nothing
            End If

            dtSearchRec1 = DPayment.GetSearchItems(intPaymentRecNo, 1)
            If dtSearchRec1.Rows.Count > 0 Then
                txtVoucherno.Text = dtSearchRec1.Rows(0).Item("PayRcptNum")
                If Me.rdbtnPayment.Checked = True Then
                    Me.txtCustVend.Text = BCommon.GetSequentialCode("VENDOR") & dtSearchRec1.Rows(0).Item("payerid")
                ElseIf Me.rdbtnReceipt.Checked = True Then
                    Me.txtCustVend.Text = BCommon.GetSequentialCode("CUST") & dtSearchRec1.Rows(0).Item("payerid")
                End If
                'txtVendId.Text = "V" & dtSearchRec1.Rows(0).Item("payerid")
                cmbName.SelectedValue = dtSearchRec1.Rows(0).Item("payerid")
                dtpickerDate.Value = dtSearchRec1.Rows(0).Item("paydate")
                cCmbPayMode.SelectedValue = dtSearchRec1.Rows(0).Item("paymode")
                txtRemark.Text = dtSearchRec1.Rows(0).Item("descr")
                txtAmount.Text = Format(dtSearchRec1.Rows(0).Item("payamount"), "0.00")
            Else
                dtSearchRec1 = Nothing
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnSearch_Click")
        Finally
            dtSearchRec1 = Nothing
            dtSearchRec2 = Nothing
        End Try
    End Sub


    '****************************************************************************
    'Written By:- Vinit(20071023)
    'Selecting Search Record
    '***********************
    Private Sub DisableControl()
        Try
            cmbName.Enabled = False
            dtpickerDate.Enabled = False
            txtCustVend.Enabled = False
            cCmbPayMode.Enabled = False
            txtRemark.Enabled = False
            txtAmount.Enabled = False
            btnSave.Visible = False
            FGPaymentdetails.Enabled = False
            FGPaymentdetails.Cols(5).Visible = False
            FGPaymentdetails.Cols(7).Visible = False
            txtBalance.Visible = False
            txtPaidAmount.Visible = False
            rdbtnPayment.Enabled = False
            rdbtnReceipt.Enabled = False
            txtAmount.Location = New Point(627, 529)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ClearData")
        End Try
    End Sub

    'Rahul : Add following sub
    'To make Amount Column ReadOnly if no item is selected
    'Col(2) = BillNo    Col(6) = Amount
    'Private Sub FGPaymentdetails_BeforeEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs) Handles FGPaymentdetails.BeforeEdit
    '    With FGPaymentdetails
    '        Select Case .Col
    '            Case 6
    '                If IsNothing(.Item(.Row, 2)) OrElse Trim(.Item(.Row, 2)) = "" Then
    '                    e.Cancel = True
    '                End If
    '        End Select
    '    End With
    'End Sub

    'Private Sub FGPaymentdetails_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles FGPaymentdetails.KeyDown
    '    If e.KeyCode = Keys.Delete Then
    '        FGPaymentdetails.Rows.Remove(FGPaymentdetails.Row)
    '        FGPaymentdetails.Rows.Count = FGPaymentdetails.Rows.Count + 1
    '    End If
    'End Sub

    'Private Sub FGPaymentdetails_LeaveCell(ByVal sender As Object, ByVal e As System.EventArgs) Handles FGPaymentdetails.LeaveCell
    '    Try
    '        If FGPaymentdetails.ColSel = 6 Then
    '            Call CalculateAmount()
    '        End If
    '    Catch ex As Exception
    '        BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "FGCheqDetails_KeyDown")
    '    End Try
    'End Sub

    '******************************************************
    'Validate All Data 
    'Modified By:- Vinit(20071023)
    '*****************************
    Private Function ValidateInfo() As Boolean
        Dim intcount As Integer = 0
        Dim intFlag As Integer = 0
        Try
            If DateTime.Compare(dtpickerDate.Value, DateTime.Now()) > 0 Then
                BCommon.ShowMsgError(10220)
                dtpickerDate.Value = DateTime.Now()
                dtpickerDate.Focus()
                Return False
            ElseIf cmbName.SelectedIndex < 1 Then
                If rdbtnPayment.Checked = True Then
                    BCommon.ShowMsgError(10221)
                ElseIf rdbtnReceipt.Checked = True Then
                    'MessageBox.Show("Please Select The Customer From the List", "Pharmacy Message")
                    BCommon.ShowMsgError(10399)
                End If
                cmbName.Focus()
                Return False
            ElseIf FGPaymentdetails.Rows.Count <= 1 Then
                BCommon.ShowMsgError(10222)
                cmbName.Focus()
                Return False
            ElseIf FGPaymentdetails.Rows.Count - 2 >= 0 Then
                For intcount = 0 To FGPaymentdetails.Rows.Count - 2
                    If FGPaymentdetails.Item(intcount + 1, 6) > 0.0 Or FGPaymentdetails.Item(intcount + 1, 6) <> Nothing Then
                        intFlag = 1
                    End If
                Next
                If intFlag = 1 Then
                    Return True
                Else
                    BCommon.ShowMsgError(10223)
                    Return False
                End If
            Else
                Return True
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnSave_Click")
        End Try
    End Function

    'Private Sub FGPaymentdetails_ValidateEdit(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.ValidateEditEventArgs) Handles FGPaymentdetails.ValidateEdit
    '    Try
    '        If e.Col = 6 Then

    '            If FGPaymentdetails.Editor.Text <> "" Then
    '                If IsNumeric(FGPaymentdetails.Editor.Text.ToString()) = False Then
    '                    BCommon.ShowMsgError(10114)
    '                    FGPaymentdetails.Editor.Text = ""
    '                    e.Cancel = True
    '                    Exit Sub
    '                ElseIf Convert.ToDouble(FGPaymentdetails.Editor.Text.ToString()) < 0 Then
    '                    'MessageBox.Show("Amount Should Be Greater Than Zero", "Pharmacy Message")
    '                    BCommon.ShowMsgError(10398)
    '                    FGPaymentdetails.Editor.Text = ""
    '                    e.Cancel = True
    '                    Exit Sub
    '                ElseIf Convert.ToDouble(FGPaymentdetails.Editor.Text.ToString()) > FGPaymentdetails.Item(e.Row, e.Col + 2) Then
    '                    BCommon.ShowMsgError(10085)
    '                    FGPaymentdetails.Editor.Text = ""
    '                    e.Cancel = True
    '                    Exit Sub
    '                End If
    '            End If
    '            FGPaymentdetails.Item(FGPaymentdetails.Row, e.Col) = FGPaymentdetails.Editor.Text
    '            Call CalculateAmount()
    '        End If
    '    Catch ex As Exception
    '        BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "FGCheqDetails_KeyDown")
    '    End Try
    'End Sub

    Private Sub txtCustVend_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCustVend.KeyDown
        If e.Alt Then Exit Sub
        If e.KeyCode = Keys.Enter Then
            'Me.cmbName.Focus()
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub txtCustVend_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCustVend.LostFocus
        Dim intVendId As Integer
        Dim dsVendorId As New DataSet
        Try
            If Me.txtCustVend.Text <> "" Then
                '*************************************************************
                'Modified By:- Vinit (20071129)
                '==============================
                If Me.rdbtnReceipt.Checked = True Then
                    dsVendorId = BVendor.GetCustId(txtCustVend.Text.ToUpper())
                ElseIf Me.rdbtnPayment.Checked = True Then
                    dsVendorId = BVendor.GetVendorId(txtCustVend.Text.ToUpper())
                End If

                If dsVendorId.Tables(0).Rows.Count > 0 Then
                    intVendId = Convert.ToInt32(dsVendorId.Tables(0).Rows(0).Item(0).ToString())
                    cmbName.SelectedValue = intVendId
                    cmbName.Focus()
                Else
                    cmbName.SelectedValue = 0
                    If Me.rdbtnReceipt.Checked = True Then
                        BCommon.ShowMsgError(10317)
                    ElseIf Me.rdbtnPayment.Checked = True Then
                        BCommon.ShowMsgError(10219)
                    End If
                    Me.txtCustVend.Text = ""
                    Me.txtCustVend.Focus()
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub rdbtnPayment_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdbtnPayment.Click
        If Me.rdbtnPayment.Checked = True Then
            Me.FGPaymentdetails.Rows.RemoveRange(1, Me.FGPaymentdetails.Rows.Count - 1)
            Me.rdbtnReceipt.Checked = False
            Me.lblVoucherno.Text = "Voucher No."
            Me.lblName.Text = "&Vendor"
            Me.txtCustVend.Text = ""
            txtVoucherno.Text = BCommon.GetSequentialID("PAYNUM")
            BCommon.SetComboValues(cmbName, BVendor.GetVendor(), "VendorID", "VendorName")
            FGPaymentdetails.Rows.Count = 21
            Me.txtAmount.Text = "0.00"
            Me.txtBalance.Text = "0.00"
            Me.txtPaidAmount.Text = "0.00"
        End If
    End Sub

    Private Sub rdbtnReceipt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdbtnReceipt.Click
        If Me.rdbtnReceipt.Checked = True Then
            Me.FGPaymentdetails.Rows.RemoveRange(1, Me.FGPaymentdetails.Rows.Count - 1)
            Me.lblVoucherno.Text = "Receipt No."
            Me.lblName.Text = "C&ustomer"
            Me.txtCustVend.Text = ""
            txtVoucherno.Text = BCommon.GetSequentialID("RCPTNUM")
            BCommon.SetComboValues(cmbName, BCustomer.GetCustomer(), "CustId", "dispname")
            FGPaymentdetails.Rows.Count = 21
            Me.txtAmount.Text = "0.00"
            Me.txtBalance.Text = "0.00"
            Me.txtPaidAmount.Text = "0.00"
        End If
    End Sub


    Private Function isUpdate() As Boolean
        Try
            If txtCustVend.Text.ToString() <> "" Then
                If Trim(txtCustVend.Text) <> txtCustVend.Tag Or Trim(txtRemark.Text) <> Trim(txtRemark.Tag) Then
                    Return True
                End If
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "isUpdate")
        End Try
    End Function

    Private Sub cCmbPayMode_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cCmbPayMode.KeyDown
        If e.KeyCode = Keys.Enter Then dtpickerDate.Focus()
    End Sub

    Private Sub dtpickerDate_ParentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpickerDate.ParentChanged

    End Sub

    Private Sub dtpickerDate_TabIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpickerDate.TabIndexChanged
        txtCustVend.Focus()
    End Sub
    
    Private Sub grpbPayment_Enter(sender As System.Object, e As System.EventArgs) Handles grpbPayment.Enter

    End Sub
End Class